package com.lecture.java8.stream;

import java.time.Duration;
import java.time.Instant;
import java.util.stream.LongStream;

/**
 * @program: spring-lecture
 * @description: 并行流
 * @author: luyn
 * @create: 2020-03-29 13:28
 **/
public class TestStream2 {

    public void test1() {
        Instant start = Instant.now();
        long sum = LongStream.rangeClosed(0, 10000000000L)
                .parallel()
                .reduce(0, Long::sum);
        Instant end = Instant.now();
        System.out.println("消耗时间：" + Duration.between(start, end).toMillis());

    }

    public static void main(String[] args) {
        TestStream2 testStream2 = new TestStream2();
        testStream2.test1();
    }
}
